/*
 * Карты
 */

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include <string.h>
#include <limits.h>
#include <stdint.h>

#ifdef DEBUG
# define debug_fprintf(x)	fprintf x
#else
# define debug_fprintf(x)	((void) 0)
#endif

#define S_assert(st) ((st)?((void)0):(void)fprintf(stderr,"Assertion (soft) \"%s\" in %s:%s():%d: failed.\n",#st,__FILE__,__func__,__LINE__))
#define SWAP_INT(a, b)	(((a) ^ (b)) && ((b) ^= (a) ^= (b), (a) ^= (b)))
#define MIN(a, b)	((a) < (b) ? (a) : (b))

#define FF(n)	(((n) & ((n) + 1)) - 1)
#define FB(n)	((n) | ((n) + 1))

/* queue */
struct queue {
	char *data;
	size_t _data_size;

	int head;
	int n;
	int _max;
};

struct fenwicktree {
	long long *data;
	long long *fwt;
	int n;
};

/* {{{ memory allocation wrappers */
extern char *
s_calloc(size_t n, size_t size)
{
	void *ptr;
#ifdef MEMDEBUG
	fprintf(stderr, "%s(): calloc %lu times %lu bytes (tot %.4f MiB)\n",
			__func__, n, size, ((float) n * size) / (1024.0f * 1024.0f));
#endif /* MEMDEBUG */
	ptr = calloc(n, size);
	if (ptr == NULL) {
		fprintf(stderr, "%s(): out of memory, failed to allocate %lu bytes\n",
				__func__, n * size);
		abort();
	}
	return ptr;
}

extern char *
s_malloc(size_t size)
{
	void *ptr;
#ifdef MEMDEBUG
	fprintf(stderr, "%s(): malloc %lu bytes (%.4f MiB)\n",
			__func__, size, (float) size / (1024.0f * 1024.0f));
#endif /* MEMDEBUG */
	ptr = malloc(size);
	if (ptr == NULL) {
		fprintf(stderr, "%s(): out of memory, failed to allocate %lu bytes\n",
				__func__, size);
		abort();
	}
	return ptr;
}

extern char *
s_realloc(char *oldptr, size_t newsize)
{
	void *newptr;
#ifdef MEMDEBUG
	fprintf(stderr, "%s(): realloc oldptr %p for new size of %lu (%.4f MiB)\n",
			__func__, oldptr, newsize, (float) newsize / (1024.0f * 1024.0f));
#endif
	newptr = realloc(oldptr, newsize);
	if (newptr == NULL) {
		fprintf(stderr, "%s(): out of memory, "
				"failed to realloc %p for new size of %lu bytes\n",
				__func__, oldptr, newsize);
		abort();
	}
#ifdef MEMDEBUG
	fprintf(stderr, "%s(): newptr %p\n", __func__, newptr);
#endif /* MEMDEBUG */
	return newptr;
}

void
s_free(void *ptr)
{
#ifdef MEMDEBUG
	fprintf(stderr, "%s(): freeing %p\n", __func__, ptr);
#endif
	free(ptr);
}
/* }}} */

/* {{{ queue */
extern struct queue *
queue__new(const int n, const size_t elem_size)
{
	struct queue *q = NULL;

	assert(n >= 1);
	assert(elem_size > 0);

	q = (struct queue *) s_malloc(sizeof *q);
	q->data = (char *) s_calloc(n, elem_size);
	q->_data_size = elem_size;
	q->head = 0;
	q->n = 0;
	q->_max = n;

	return q;
}

extern int
queue__push(struct queue *q, const void *p)
{
	assert(q != NULL);
	assert(p != NULL);

	if (q->n >= q->_max) {
		#ifdef QUEUE_DEBUG
		fprintf(stderr, "%s(): q->n (%d) >= q->_max (%d), can't push any deeper :-(\n",
				__func__, q->n, q->_max);
		#endif /* QUEUE_DEBUG */
		return -1;
	}

	memcpy(q->data + ((q->head + q->n++) % q->_max) * q->_data_size, p, q->_data_size);
	#ifdef QUEUE_DEBUG
	fprintf(stderr, "%s(): q->head=%d, q->n=%d\n",
			__func__, q->head, q->n);
	#endif /* QUEUE_DEBUG */

	return 0;
}

extern int
queue__pop(struct queue *q, void *buf)
{
	assert(q != NULL);
	assert(buf != NULL);

	memcpy(buf, q->data + (q->head) * q->_data_size, q->_data_size);
	q->head = (q->head + 1) % q->_max;
	q->n--;
	#ifdef QUEUE_BEBUG
	fprintf(stderr, "%s(): q->head=%d, q->n=%d\n",
			__func__, q->head, q->n);
	#endif /* QUEUE_DEBUG */

	return 0;
}

extern int
queue__cleanup(struct queue *q)
{
	S_assert(q != NULL);
	if (q == NULL)
		return -1;

	if (q->_max == 0 || q->data == NULL)
		return 1;

	s_free(q->data);
	q->data = NULL;
	s_free(q);

	return 0;
}
/* }}} */

int
update(struct fenwicktree *F, const long long newval, const int idx)
{
	register long long diff;
	register int i;

	i = idx;
	diff = newval - F->data[i];
	F->data[idx] = newval;

	while (i < F->n) {
		F->fwt[i] += diff;
		i = FB(i);
	}

	return 0;
}

long long
sum(struct fenwicktree *F, const int end)
{
	register int i = end;
	register long long res = 0;

	while (i >= 0) {
		res += F->fwt[i];
		i = FF(i);
	}

	return res;
}

/*{{{*/
long long
range_sum_incl(struct fenwicktree *F, const int start, const int end)
{
	return sum(F, end) - sum(F, start - 1);
}

long long
range_sum(struct fenwicktree *F, const int start, const int end)
{
	return sum(F, end) - sum(F, start);
}
/*}}}*/

int
main(int argc, char **argv)
{
	static char line[1024];
	int arg[2];
	struct fenwicktree FWT;
	register int i;

	fgets(line, sizeof line, stdin);
	sscanf(line, "%d %*d\n", &FWT.n);
	FWT.data = s_calloc(FWT.n, sizeof *FWT.data);
	FWT.fwt = s_calloc(FWT.n, sizeof *FWT.fwt);

	while (fgets(line, sizeof line, stdin)) {
		switch (line[0]) {
		case 'T': case 't':
			sscanf(line, "%*c %d %d\n", &arg[0], &arg[1]);
			--arg[0],arg[1]--;
			/* for (i = arg[0]; i <= arg[1]; i++)
			 *         update(&FWT, FWT.data[i] + 1, i);
			 */
			for (i = arg[0]; i < FWT.n; i = FB(i))
				FWT.fwt[i] += 1;
			for (i = arg[1] + 1; i < FWT.n; i = FB(i))
				FWT.fwt[i] += 1;
			break;
		case 'Q': case 'q':
			sscanf(line, "%*c %d\n", &arg[0]);
			--arg[0];
			/* printf("%lld\n", range_sum_incl(&FWT, arg[0], arg[0])); */
			fprintf(stdout, "%lld\n", sum(&FWT, arg[0]) & 1LL);
			break;
		}
	}

	s_free(FWT.data);
	s_free(FWT.fwt);

	return 0;
}
